<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"/>
    <title>悦章科技机构平台</title>
    <script src="/Public/static/jquery-2.0.3.min.js"></script>
    <script src="/Public/static/layer/layer.js"></script>
    <!--内容样式-->
    <link rel="stylesheet" href="__PUBLIC__/Home/css/style.css" />
</head>
<body>

<div class="main">
    <!--  头部  -->
    <include file="menu" />

    <!--  右侧内容  -->
    <div class="content">
        <div class= "ct-title">
            <div class="ctt-bt">班级分类</div>
            <div class="ctt-r">
                <form class="cttr-bd">
                    <a class="cttrb-xz" onclick="addClassClassification()">新增分类</a>
                    <div class="divclear"></div>
                </form>
                <div class="divclear"></div>
            </div>
            <div class="divclear"></div>
        </div>


        <div class="bjfl-box">

            <div class="ct-fl">
                <div class="ctf-title">
                    <div class="ctft1">分类名称</div>
                    <div class="ctft1">排序</div>
                    <div class="ctft2">操作</div>
                    <div class="divclear"></div>
                </div>

                <div class="ctf-box">
                    <volist name="_list" id="vo">
                        <div class="ctfb-yj">
                            <div class="ctfby-mc">
                                <img src="__PUBLIC__/Home/images/icon_hidden.png" class="hideChild"/>
                                <span>{$vo.name}</span>
                                <div class="divclear"></div>
                            </div>
                            <div class="ctfby-px">{$vo.sort}</div>
                            <div class="ctfby-cz">
                                <a onclick="editParent('{$vo.id}','{$vo.name}','{$vo.sort}')">编辑</a>
                                <a href="{:U('Home/Educational/delClassClassification',array('id'=>$vo['id']))}">删除</a>
                                <a onclick="addChild('{$vo.id}','{$vo.name}')">添加子分类</a>
                            </div>
                            <div class="divclear"></div>
                        </div>
                        <notempty name="vo.child">
                            <ul class="ctfb-ej">
                                <volist name="vo.child" id="item">
                                    <li>
                                        <div class="ctfbe-mc">{$item.name}</div>
                                        <div class="ctfbe-px">{$item.sort}</div>
                                        <div class="ctfbe-cz">
                                            <a onclick="editChild('{$item.id}','{$vo.id}','{$vo.name}','{$item.name}','{$item.sort}')">编辑</a>
                                            <a href="{:U('Home/Educational/delClassClassification',array('id'=>$item['id']))}">删除</a>
                                        </div>
                                        <div class="divclear"></div>
                                    </li>
                                </volist>
                            </ul>
                        </notempty>
                    </volist>
                </div>

                <!--<div class="ctf-box">
                    <div class="ctfb-yj">
                        <div class="ctfby-mc">
                            <img src="__PUBLIC__/Home/images/icon_show.png" />
                            <span>XXXX一级类目</span>
                            <div class="divclear"></div>
                        </div>
                        <div class="ctfby-px">2</div>
                        <div class="ctfby-cz">
                            <a onClick="document.getElementById('tck-yjfl').style.display='block'">编辑</a>
                            <a>删除</a>
                            <a onclick="document.getElementById('tck-ejfl').style.display='block'">添加子分类</a>
                        </div>
                        <div class="divclear"></div>
                    </div>
                </div>

                <div class="ctf-box">
                    <div class="ctfb-yj">
                        <div class="ctfby-mc">
                            <img src="__PUBLIC__/Home/images/icon_show.png" />
                            <span>XXXX一级类目</span>
                            <div class="divclear"></div>
                        </div>
                        <div class="ctfby-px">3</div>
                        <div class="ctfby-cz">
                            <a onClick="document.getElementById('tck-yjfl').style.display='block'">编辑</a>
                            <a>删除</a>
                            <a onclick="document.getElementById('tck-ejfl').style.display='block'">添加子分类</a>
                        </div>
                        <div class="divclear"></div>
                    </div>
                </div>-->
            </div>
        </div>
    </div>
</div>

<!-- 新增一级分类 弹出框-->
<!--<div class="tck-demo" id="tck-yjfl">-->

    <!--<div class="tk-box" style="width: 400px;height: 350px;">-->
        <!--<div class="tkb-title">-->
            <!--<div class="tkbt-bt">新增一级分类</div>-->
            <!--<div class="tkbt-close" onClick="document.getElementById('tck-yjfl').style.display='none'">-->
                <!--<img src="__PUBLIC__/Home/images/icon_delete.png" />-->
            <!--</div>-->
            <!--<div class="divclear"></div>-->
        <!--</div>-->
        <!--<div class="tkb-zdfp">-->
            <!--<div class="tkbz-box">-->
                <!--<input type="text" placeholder="请输入一级类目名称" class="tkbzb-l" name="name">-->
                <!--<div class="divclear"></div>-->
            <!--</div>-->
            <!--<div class="tkbz-box">-->
                <!--<input type="text" placeholder="请输入序号" class="tkbzb-l">-->
                <!--<div class="divclear"></div>-->
            <!--</div>-->
        <!--</div>-->
        <!--<div class="tkb-qr">确定</div>-->
    <!--</div>-->

<!--</div>-->

<!-- 新增二级分类 弹出框-->
<div class="tck-demo" id="tck-ejfl">
    <div class="tk-box" style="width: 400px;height: 350px;">
        <input type="hidden" name="id"/>
        <input type="hidden" name="cc_id"/>
        <div class="tkb-title">
            <div class="tkbt-bt">新增二级分类</div>
            <div class="tkbt-close" onClick="document.getElementById('tck-ejfl').style.display='none'">
                <img src="__PUBLIC__/Home/images/icon_delete.png" />
            </div>
            <div class="divclear"></div>
        </div>
        <div class="tkb-zdfp">
            <div id="superior" class="tkbz-box" style="background: #f5f5f5;">
                <input type="text" placeholder="XXXX一级类目" class="tkbzb-l" id="one_class_name" disabled>
                <div class="divclear"></div>
            </div>
            <div class="tkbz-box">
                <input type="text" placeholder="请输入二级类目名称" class="tkbzb-l" name="name">
                <div class="divclear"></div>
            </div>
            <div class="tkbz-box">
                <input type="text" placeholder="请输入序号" class="tkbzb-l" name="sort">
                <div class="divclear"></div>
            </div>
            <!--<div class="tkbz-box">
                <select>
                    <option>选择排序</option>
                </select>
            </div>-->
        </div>
        <div class="tkb-qr" onclick="saveClassClassification()">确定</div>
    </div>
</div>
</body>
<script type="text/javascript">
    //新增一级分类
    function addClassClassification()
    {
        $(".tkbt-bt").text("新增一级分类");
        $("#superior").hide();
        $("input[name='id']").val("");
        $("input[name='cc_id']").val("");
        $("input[name='name']").val("");
        $("input[name='sort']").val("");
        $("#tck-ejfl").show();
    }

    //编辑一级分类
    function editParent(id,name,sort)
    {
        $(".tkbt-bt").text("新增一级分类");
        $("#superior").hide();
        $("input[name='id']").val(id);
        $("input[name='cc_id']").val("");
        $("input[name='name']").val(name);
        $("input[name='sort']").val(sort);
        $("#tck-ejfl").show();
    }

    //新增二级分类
    function addChild(cc_id,name){
        $(".tkbt-bt").text("新增二级分类");
        $("#superior").show();
        $("#one_class_name").val(name);
        $("input[name='id']").val("");
        $("input[name='cc_id']").val(cc_id);
        $("input[name='name']").val("");
        $("input[name='sort']").val("");
        $("#tck-ejfl").show();
    }

    //编辑二级分类
    function editChild(id,cc_id,one_name,name,sort)
    {
        $(".tkbt-bt").text("新增二级分类");
        $("#superior").show();
        $("#one_class_name").val(one_name);
        $("input[name='id']").val(id);
        $("input[name='cc_id']").val(cc_id);
        $("input[name='name']").val(name);
        $("input[name='sort']").val(sort);
        $("#tck-ejfl").show();
    }

    //提交分类
    function saveClassClassification()
    {
        var id = $("input[name='id']").val();
        var cc_id = $("input[name='cc_id']").val();
        var name = $("input[name='name']").val();
        var sort = $("input[name='sort']").val();
        var url = "{:U('Home/Educational/saveClassClassification')}";
        $.ajax({
            type: "POST", //类型get，post
            url: url, //链接地址
            data:{"id":id,"cc_id":cc_id,"name":name,"sort":sort},//参数，一般post用
            success: function(data){
                var dataObj = JSON.parse(data);
                //成功后函数
                layer.msg(dataObj.msg);
                location.href="{:U('Home/Educational/classClassification')}";
            },
            error:function(){
                //失败时函数
                layer.msg("失败");
            }
        })
    }

    //隐藏二级分类
    $('.hideChild').each(function(e){
        $(this).click(function(){
            if($(this).attr('src') == '__PUBLIC__/Home/images/icon_hidden.png'){
                $(".ctfb-ej").eq(e).hide();
                $(this).attr("src","__PUBLIC__/Home/images/icon_show.png");
            }else {
                $(".ctfb-ej").eq(e).show();
                $(this).attr("src","__PUBLIC__/Home/images/icon_hidden.png");
            }
            //__PUBLIC__/Home/images/icon_hidden.png
        })
    })
</script>
</html>
